//
//  FriendViewController.m
//  FPTest
//
//  Created by zhaohong on 2017/11/9.
//  Copyright © 2017年 zhaohong. All rights reserved.
//

#import "FriendViewController.h"
#import "FriendIPModel.h"
@interface FriendViewController ()
@property (nonatomic,strong)FriendIPModel *friendModel;
@property (weak, nonatomic) IBOutlet UITextField *textFied;
@property (weak, nonatomic) IBOutlet UITextView *containTextV;


@end

@implementation FriendViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"好友";
    
  
}

#pragma mark ---------Actions--------

- (IBAction)resetAction {
    self.textFied.text = @"53.223.108.40";
    self.containTextV.text = @"";
    [self.textFied resignFirstResponder];
}

- (IBAction)searcheAction {
    [self requestData];
     self.containTextV.text = @"";
    [self.textFied resignFirstResponder];
}



#pragma mark 请求网路
- (void)requestData
{
    [super requestData];
    NSMutableDictionary *muDic = [NSMutableDictionary dictionary];
    [muDic setObject:self.textFied.text forKey:@"ip"];
    [muDic setObject:@"json" forKey:@"format"];
    
    //key值必须和上面定义的属性名一致
    [WebServiceHelper postAndGetJsonModelWithURLString:@"iplookup/iplookup.php" parameters:muDic modelClass:[FriendIPModel class] requester:self key:@"friendModel" success:^(BaseModel *baseModel) {
        [self requestSuccess];
        self.containTextV.text = self.friendModel.country;
    } failure:^(NSError *error) {
        self.isLoading = NO;
        self.containTextV.text = @"请求数据错误";
    }];
    

}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
